import { Component, OnInit, ViewChild } from "@angular/core";
import "datatables";
import { ApprInfo } from "./appr-info.class";
import { PublishManService } from "./publishing.service";
import { DataTablesComponent, DataTablesComponentConfig } from "app/theme/components/dataTables";
import { provinces } from 'app/constants/provinces';

@Component({
  selector: 'publishing',
  templateUrl: 'publishing.component.html',
  styleUrls: ['publishing.component.scss'],
  providers: [PublishManService]
})
export class PublishComponent implements OnInit {
  @ViewChild(DataTablesComponent) dataTable: DataTablesComponent;

  private applyTableUrl: string = '/water/boards/publicShowList';
  private searchForm: SearchForm = new SearchForm();
  private provinces = provinces;

  private _errorMsg: string;
  private errorShow = false;

  private dataTablesConfig: DataTablesComponentConfig = new DataTablesComponentConfig();

  constructor() {
  }

  search() {
    this.dataTable.draw();
  }

  ngOnInit() {
    this.dataTablesConfig.ajaxUrl = this.applyTableUrl;
    this.dataTablesConfig.selectable = false;
    this.dataTablesConfig.columnsDef = [
      {'name': '证书类型', 'id': 'type'},
      {'name': '姓名', 'id': 'name'},
      {'name': '出生年月', 'id': 'birthday'},
      {'name': '省份', 'id': 'province'},
      {'name': '公司名', 'id': 'companyname'},
      {'name': '开始时间', 'id': 'startdate','orderable': true},
      {'name': '结束时间', 'id': 'enddate'},
      {'name': '成绩', 'id': 'score'},
    ];
  }

  handleError(e:any){
    if(e.type == 'error'){
      this.errorShow = true;
    }
  }

  onHideModal(): void {
    jQuery('.modal-backdrop').remove();
  }
}

export class SearchForm {
  public companyname: string = '';
  public name: string = '';
  public birthday: string = '';
  public type: string = '';
  public province: string = '';
}
